package com.zking.seckillpro.util;

import lombok.Data;

/**
 * 响应封装类，用于定义统一的返回结果
 * @param <T>
 */
@Data
public class JsonResponseBody<T> {

    private int code;//状态码
    private String msg;//状态信息
    private T data;//传到前端的响应数据
    private long  total;//分页查询总记录数

    public JsonResponseBody(){
        this.code=JsonResponseStatus.SUCCESS.getCode();
        this.msg=JsonResponseStatus.SUCCESS.getMsg();
    }
    //带有状态参数的构造方法
    public JsonResponseBody(JsonResponseStatus jsonResponseStatus){
        this.code=jsonResponseStatus.getCode();
        this.msg=jsonResponseStatus.getMsg();
    }
    //针对数据的构造方法
    public JsonResponseBody(T data){
        this.code=JsonResponseStatus.SUCCESS.getCode();
        this.msg=JsonResponseStatus.SUCCESS.getMsg();
        this.data=data;
    }

    //针对分页的构造方法
    public JsonResponseBody(T data ,long total){
        this.code=JsonResponseStatus.SUCCESS.getCode();
        this.msg=JsonResponseStatus.SUCCESS.getMsg();
        this.data=data;
        this.total=total;
    }
}
